#include <iostream>
#include <boost/filesystem/path.hpp>
#include <string>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <boost/regex.hpp>
#include "get_arg.h"
using std::string;
using std::ofstream;
using std::ifstream;
using std::fstream;
using std::cerr;
using std::cout;


// my functions
#include <print_error.h>
#include <program_options_helper.h>
#include <open_fstream.h>

using namespace program_options_helper;
namespace po = boost::program_options_lg;










//_______________________________________________________________________________________

//		process_command_line_options


//_______________________________________________________________________________________
bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{
	//
	// mandatory arguments
	//
	po::options_description mandatory_args("Mandatory Arguments");
	mandatory_args.add_options()
	("input_file,i", 	po::value<string>(&args.input_file)
								->set_name("FILE"),
								"Input lines. ")
	("same_file,s", 	po::value<string>(&args.identical_file)
								->set_name("FILE"),
								"Identical lines. ")
	("collision_file,c", 	po::value<string>(&args.collision_file)
								->set_name("FILE"),
								"collision lines. ");

	args.add_std_options();
	po::options_description all_args("");
	all_args.add(mandatory_args).add(args.optional_args);


	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(	cerr, *argv, "1.0\n"
						"\tHistory: \n\n"
						"\tv 1.0\1"
						"Initial version\n"
			);
		return false;
	}
	if (vm.count("help"))
	{
		string exe_description =
				"Tests for collisions in hash functions."	;

		print_usage(cerr, string(*argv), 	"[OPTIONS]\n"
											"--input_file FILE\n",
							all_args, exe_description, 80);
		return false;
	}
	check_required_options(vm, mandatory_args);



	// make sure each file is valid
	args.input_file_size = open_fstream(args.f_input, args.input_file);
	args.input_file = boost::filesystem::path(args.input_file).leaf();

	args.open_err_log();
	return true;
}




